<% layout('/layouts/default.html', {title: '评分汇总', libs: ['layout','dataGrid']}){ %>
<div class="ui-layout-west">
	<div class="main-content">
		<div class="box box-main">
			<div class="box-header" style="padding-bottom: 4px;">
				<div class="box-title">
					<i class="fa icon-grid"></i> ${text('被考核单位')}
				</div>
			</div>
			<div class="box-body">
				<div class="input-group">
					<#form:input path="unitName" maxlength="100" class="form-control " placeholder="请输入单位名称" autocomplete="off"/>
					<span class="input-group-addon"  style="cursor: pointer" onclick="searchTaskDesc()">查询</span>
					<span class="input-group-addon" onclick="reset()" style="cursor: pointer">重置</span>
				</div>
			</div>
			<div class="ui-layout-content">
				<table id="leftDataGrid"></table>
			</div>
		</div>
	</div>
</div>
<div class="ui-layout-center">
	<iframe id="mainFrame" name="mainFrame" class="ui-layout-content p0"></iframe>
</div>
<% } %>
<script>
	// 初始化布局
	$('body').layout({
		west__initClosed: $(window).width() <= 767, // 是否默认关闭
		west__size: 200,
		onresize_end: function(){
			$('#leftDataGrid').dataGrid('resize');
		}
	});
	// 主页框架
	var win = $("#mainFrame")[0].contentWindow;
	// 树结构初始化加载

	// 调用子页分页函数
	function page(){
		win.page();
	}
	$(window).resize(function () {

	});
	$('#leftDataGrid').dataGrid({
		data: ${toJson(assessmentUnit)},
		datatype: "local", // 设置本地数据
		sortableColumn:false, // 禁止排序
		columnModel: [
			{header:'${text("任务id")}', name:'examId',hidden:true, width:150, align:"left"},
			{header:'${text("状态")}', name:'exameStatus',hidden:true, width:150, align:"left"},
			{header:'${text("被考核单位code")}', name:'exameOrg',hidden:true, width:150, align:"left"},
			{header:'${text("被考核单位")}', name:'exameOrgName', width:150, align:"left",formatter: function(val, obj, row, act){
						if (row.sumScoreStatus=='2'){
							return val+'<span style="color: red">(关键指标评分未提交)</span>'
						}
						if (row.sumScoreStatus=='3'){
							return val+'<span style="color: red">(单项指标评分未提交)</span>'
						}
						if (row.sumScoreStatus=='9'){
							return val+'<span style="color: red">(未提交)</span>'
						}
						if(row.sumScoreStatus=='0'){
							return val+'<span style="color: dodgerblue">(已提交)</span>'
						}
					return val;
				}},
			{header:'${text("状态码")}', name:'sumScoreStatus',hidden:true, width:150, align:"left"},
		],
		autoGridHeight: function(){
			var height = $(window).height()-170;
			return height;
		},
		emptyDataHint: true,
		// 选择行后调用（id:行id，isSelect：是否是选中，event：事件）
		onSelectRow: function(id, isSelect, event) {
			let selectRow = $('#leftDataGrid').dataGrid('getRowData', id);
			// if (selectRow.sumScoreStatus=='2'){
			// 	js.alert('当前被考核单位关键指标评分未提交无法进行评分汇总！', {icon: 2}, function(){})
			// 	$('#mainFrame').attr('src','');
			// }else if (selectRow.sumScoreStatus=='3'){
			// 	// js.alert('当前被考核单位单项指标评分未提交无法进行评分汇总！', {icon: 2}, function(){})
			// 	js.confirm('当前被考核单位单项指标评分未提交无法进行评分汇总！是否催办?','${ctx}/score/dcSupExamDXZBScore/cuiban?examId='+selectRow.examId+'&exameOrg='+selectRow.exameOrg,null,function(res){js.alert(res.message, {icon: 1}, function(){})},null,null)
			// 	$('#mainFrame').attr('src','');
			// }
			// else {
				$('#mainFrame').attr('src', '${ctx}/score/dcSupExamSumScore/subView?examId='+selectRow.examId+'&exameOrg='+selectRow.exameOrg+'&scoreStatus='+selectRow.sumScoreStatus);
			//}
		},
		// 加载成功后执行事件
		ajaxSuccess: function(data){
			if (data.records>0){
				changePage(data,'${selectExamOrg}')
			}

			$('#leftDataGrid tr').click(function(){
				$(this).siblings().removeClass('SelectBG');
				$(this).addClass('SelectBG');
			})
		}
	});






	function changePage(data,exameOrg){
		if (exameOrg!=null&&exameOrg!=''){
			for (let i = 0; i <data.rows.length; i++) {
				if (data.rows[i].exameOrg==exameOrg){
					$('#leftDataGrid').dataGrid('setSelectRow',(i+1), false);
					$('#leftDataGrid tr').eq(i+1).addClass('SelectBG')
					break;
				}
			}
		}else {
			// let row=data.rows;
			// for (let i = 0; i <row.length; i++) {
			// 	 if (row[i].sumScoreStatus=='0' || row[i].sumScoreStatus=='9'){
			// 		 $('#leftDataGrid').dataGrid('setSelectRow',(i+1), false);
			// 		 $('#leftDataGrid tr').eq(i+1).addClass('SelectBG')
			// 		 return;
			// 	 }
			// }
			$('#leftDataGrid').dataGrid('setSelectRow',1, false);
			$('#leftDataGrid tr').eq(1).addClass('SelectBG')
		}
	}



	function searchTaskDesc() {
		// 获取用户输入查询项
		let tempTaskDesc = $("#unitName").val();
		if(tempTaskDesc != '' && tempTaskDesc != undefined){
			// 记录目标值
			let targetList = [];
			// 遍历表格数据，获取目标值
			let tempList = ${toJson(assessmentUnit)}
			for(let i = 0; i < tempList.length; i++){
				if(tempList[i].exameOrgName.indexOf(tempTaskDesc) != -1){
					targetList.push(tempList[i]);
				}
			}
			// 刷新表格数据
			$('#leftDataGrid').dataGrid('setParam', {
				data:targetList
			}, true).dataGrid('reloadGrid');
		}else {
			$('#leftDataGrid').dataGrid('setParam', {
				data:${toJson(assessmentUnit)}
			}, true).dataGrid('reloadGrid');
		}
	}

	// 重置表格数据
	function reset() {
		// 重置查询项
		$("#unitName").val('');
		// 重置表格数据
		$('#leftDataGrid').dataGrid('setParam', {
			data:${toJson(assessmentUnit)}
		}, true).dataGrid('reloadGrid');
	}
</script>
<style>
	.SelectBG td{
		background: #eaeaea !important;
		background-color: #eaeaea !important;
		color:blue;
	}
</style>